<?php defined('InNcPHP') or exit('Access Invalid!');?>

<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <h3><?php echo $lang['advert_index'];?></h3>
            <?php echo $output['top_link'];?>
        </div>
    </div>
    <div class="fixed-empty"></div>
    <form id="add_form" method="post" enctype="multipart/form-data">
        <input type="hidden" name="form_submit" value="ok" />
        <input type="hidden" name="advert_id" value="<?php echo $output['advertInfo']['advert_id']?>" />
        <table class="table tb-type2 nobdb">
            <tbody>
            <tr class="noborder">
                <td colspan="2" class="required"><label class="validation" for="advert_name"><?php echo $lang['advert_index_advert_name'];?>:</label></td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" id="advert_name" name="advert_name" class="txt" value="<?php echo $output['advertInfo']['advert_name']?>"></td>
                <td class="vatop tips"><?php echo $lang['advert_index_advert_name_tip']; ?></td>
            </tr>
            <tr>
                <td colspan="2" class="required"><label class="validation" for="advert_type"><?php echo $lang['advert_index_advert_type'];?>:</label></td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform">
                    <select name="advert_type">
                        <option value=""><?php echo $lang['nc_common_select'] ?></option>
                        <?php foreach((array)$output['advert_type_list'] as $k=>$v){?>
                            <option  value="<?php echo $k;?>" <?php if($output['advertInfo']['advert_type']==$k) echo 'selected' ?>  ><?php echo $v;?></option>
                        <?php }?>
                    </select>
                </td>
                <td class="vatop tips"></td>
            </tr>
            <!-- 图片 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation"><?php echo $lang['advert_index_advert_image'];?>:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform">
                    <span class="type-file-show">
                        <img class="show_image" src="<?php echo ADMIN_TEMPLATES_URL;?>/images/preview.png">
                        <div class="type-file-preview" style="display: none;">
                            <img id="view_img" src="<?php echo UPLOAD.'product/'.$output['advertInfo']['advert_image'];?>" style="max-height: 100px;">
                        </div>
                    </span>
                    <span class="type-file-box">
                        <input type='text' name='textfield' id='textfield' class='type-file-text' />
                        <input type='button' name='button' id='button' value='' class='type-file-button' />
                        <input name="advert_image" type="file" class="type-file-file" id="image" size="30" hidefocus="true" />
                    </span>
                </td>
                <td class="vatop tips">轮播图片大小 1080 * 430，美食图片400 * 400</td>
            </tr>
            <tr>
                <td colspan="2" class="required"><?php echo $lang['advert_index_advert_url'];?>:</label></td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" id="advert_url" name="advert_url" class="txt" value="<?php echo $output['advertInfo']['advert_url']?>"></td>
                <td class="vatop tips"></td>
            </tr>
            <tr>
                <td colspan="2" class="required"><label class="validation"><?php echo $lang['advert_sort']; ?>:</label></td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" id="advert_sort" name="advert_sort" class="txt" value="<?php echo $output['advertInfo']['advert_sort']?>"></td>
                <td class="vatop tips"><?php echo $lang['advert_sort_tip']; ?></td>
            </tr>
            </tbody>
            <tfoot>
            <tr class="tfoot">
                <td colspan="2"><a href="JavaScript:void(0);" class="btn" id="submitBtn"><span><?php echo $lang['nc_submit'];?></span></a></td>
            </tr>
            </tfoot>
        </table>
    </form>
</div>
<script>
    //图片文件选择
    $("#image").change(function(){
        $("#textfield").val($(this).val());
    });

    var addForm = $("#add_form");
    //表单验证
    addForm.validate({
        errorPlacement: function(error, element){
            if (element.attr('id') === 'image') {
                error.appendTo(element.parent().parent().parent().prev().find('td:first'));
            } else {
                error.appendTo(element.parent().parent().prev().find('td:first'));
            }
        },
        rules : {
            advert_name : {required : true, minlength: 2, maxlength: 20 },
            advert_type:{ required : true},
            advert_sort: {
                digits: true,
                min: 0,
                max: 9999999999
            }
        },
        messages : {
            advert_name : {
                required : '<?php echo $lang['advert_add_name_null'];?>',
                minlength: '<?php echo $lang['advert_add_name_length'];?>',
                maxlength: '<?php echo $lang['advert_add_name_length'];?>'
            },
            advert_type:{ required : '<?php echo $lang['advert_add_advert_type_null']?>'},
            advert_sort: {
                digits: '<?php echo $lang['advert_sort_tip'];?>',
                min: '<?php echo $lang['advert_sort_tip'];?>',
                max: '<?php echo $lang['advert_sort_tip'];?>'
            }
        }
    });
    //按钮先执行验证再提交表单
    $("#submitBtn").click(function(){
        addForm.valid() && addForm.submit();
    });

</script>
